package tech.yunland.shop.web;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import tech.yunland.shop.domain.service.ImportExcelService;

import com.moyuer.bsf.domain.dao.AttachmentDao;
import com.moyuer.bsf.web.controller.BaseController;

/**
 * 导入Excel接口
 * 
 * @author 王睿智<geekrize@gmail.com>
 * 
 */
@RestController
@RequestMapping("/excel")
public class ResolveExcelController extends BaseController {

	@Autowired
	private AttachmentDao attachmentDao;

	@Autowired
	private ImportExcelService importExcelService;

	/**
	 * 导入会员初始化Excel接口
	 * 
	 * @param excelId
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/", method = RequestMethod.POST)
	public boolean importExcel(@RequestParam String excelId,@RequestParam String import_Type) throws IOException {


		String excel_type = null;// Excel版本

		String fileName = importExcelService.getFileName(excelId);
		// 获取excel版本
		excel_type = fileName.substring(fileName.length() - 1);
		// 判断excel文件类型
		if (excel_type.equals("s")) {
			importExcelService.parseHSSFWorkbook(fileName, primaryOrganId,import_Type,this.currentUserId);
		} else if (excel_type.equals("x")) {
			importExcelService.parseXSSFWorkbook(fileName, primaryOrganId,import_Type,this.currentUserId);
		} else{
			throw new RuntimeException("导入失败：导入文件类型错误");
		}
        return true;
	}

}
